/**
 * \brief Function safe/unsafe version dependent on template parameter.
 *
 * \author Bartosz Kedra (bartosz.kedra@gmail.com)
 */
#include <stdexcept>
#include <assert.h>
#include <iostream>

template <int size> struct safe
{
   static void check(int index) throw (std::out_of_range)
   {
      if (index < 0 || index > size)
      {
         throw std::out_of_range("Array range exception");
      }
   }
};

template <int size> struct unsafe
{
   static void check(int index) {};
};

template <typename T, int size,
          template <int size> class AccessType = safe>
class Array
{
public:

   T& operator[](int index)
   {
      AccessType<size>::check(index);
      return tab[index];
   }

private:

   T tab[size];
};

int main()
{
   Array<char, 100> array;
   try
   {
      array[101];
      assert(false);
   }
   catch (std::out_of_range exception)
   {
      std::cout<< exception.what() << std::endl;
   }

   return 0;
}
